<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .con{
            width: 500px;
            border: 2px solid red;
            margin: 0 auto;/*垂直居中*/
            overflow: hidden;
        }
        .con .item{
            width: 100px;
            height: 100px;
            text-align: center;
            float: left;
        }
    </style>
</head>
<body>
    <div class="con" id="con">
        <div class="item">
            <img src="images/animal1.png" />
        </div>
        <div class ="item" id="item2">
            <img src="images/animal2.png" />
        </div>
        <div class="item">
            <img src="images/animal6.png" style="height: 80px;" />
        </div>
        <div class="item">
            <img src="images/animal4.png" id = "img4" />
        </div>
    </div>
</body>
<script>
    var item2 = document.getElementById("item2");
    item2.onclick = function(){
        item2.previousElementSibling.style.backgroundColor = "yellow";
        this.nextElementSibling.style.backgroundColor = "blue";
    }
</script>
</html> 